package com.econ.powercloud.ems.kafka.strategy;

import com.econ.powercloud.ems.common.interf.AbstractEconBusProcess;
import com.econ.powercloud.ems.common.pojo.CacheOperationVO;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author : zjf
 * @Description : 刷新计算缓存的入口
 * @Date : 2023/3/2 10:26
 * @Modified by : zjf
 */
@Component
public class EconCommonBusStrategy {

    @Autowired
    private List<AbstractEconBusProcess> econBusProcessList;

    private Map<Integer, AbstractEconBusProcess> processMap = Maps.newHashMap();

    @PostConstruct
    private void init() {
        processMap = econBusProcessList.stream().collect(Collectors.toMap(d->d.getCacheTopicType().getCode(), item -> item));
    }

    public void operationCache(CacheOperationVO cacheOperationVO){
        AbstractEconBusProcess process = processMap.get(cacheOperationVO.getTopicType().getCode());
        if (process == null) {
            return;
        }
        process.operation(cacheOperationVO);
    }
}
